<?php

/*
 * Action
 * 
 * +2 Cards; +2 Actions
 * 
 * Discard 2 cards.
 * 
 * When you gain this, look through your discard pile (including this),
 * reveal any number of Action cards from it, and shuffle them into your deck.
 */

class Inn extends Card implements iKingdom, iHinterlands, iAction {
    
    public function __construct() {
        parent::__construct("Inn", 5);
    }
    
    public function getDescription() {
        return array(
            "+2 Cards",
            "+2 Actions",
            "Discard 2 cards",
            "When you gain this, look through your discard pile (including this), reveal any number of Action cards from it, and shuffle them into your deck.");
    }
    
    public function play(Game $game, $isRealCard) {
        // +2 cards, +2 actions
        $game->addActions(2);
        $drawed_cards = $game->drawCards(2);
        ScreenDisplay::addScreenMessage($game, true, "get +2 action and draw " . nicePrint($drawed_cards), "gets +2 action and draws " . sizeof($drawed_cards) . " cards");
        
        // discard 2 cards
        $playHand = $game->getPlayHand();
        if (sizeof($playHand) > 2) {
            $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHand, 2, 2, null, "Discard 2 cards");
            ScreenDisplay::addScreenMessage($game, false, " and discard" . nicePrint($output), " and discards " . sizeof($output) . " cards");
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }
        } else {
            ScreenDisplay::addScreenMessage($game, false, " and discard" . nicePrint($playHand), " and discards " . sizeof($playHand) . " cards");
            $game->discardPlayHand();
        }
        $game->cardActionFinished();
        return true;
    }
    
    public function afterGainThisCard(Game $game, $name = null){
        $options = array();
        $discard = $game->getDiscardDeck($name);
        foreach ($discard as $card) {
            if (!$card instanceof iAction)
                continue;
            else
                $options[] = $card;
        }
        if (sizeof($options) > 0) {
            $output = MySocket::GetUserReply($game, Input_ChooseMany, $options, 0, sizeof($options), null, "Choose cards to put in your deck", $name);
            ScreenDisplay::addScreenMessage($game, true, "reshuffle " . nicePrint($output) . " into your deck", "reshuffles " . ScreenDisplay::$LMSG . " into his deck", $name);
            foreach ($output as $card) {
                $game->moveCardFromPileToPile($card, DiscardPile, DrawPile, $name);
            }
            if (sizeof($output) > 0) {
                $game->shuffleDrawDeck($name);
            }
        }
      
        return true;
    }
}

?>
